example 1
=================
#include <iostream.h>
#include <string.h>
#include <conio.h>
void main(void)
{
clrscr();
char firstString[40], secondString[40];
cout << "Enter a string: ";
cin.getline(firstString, 40);
cout << "Enter another string: ";
cin.getline(secondString, 40);
if (strcmp(firstString, secondString) == 0)
cout << "You entered the same string twice.\n";
else
cout << "The strings are not the same.\n";

getch();

}


example2:
============


#include <iostream.h>
#include <string.h>
#include <conio.h>
void main(void)
{
clrscr();
float aprice = 249.0, Bprice = 299.0;
char partNum[8];

cout << "Enter the part number of the stereo you\n";
cout << "wish to purchase: ";
cin >> partNum;
if (strcmp(partNum, "S147-29A") == 0)  
cout << "The price is $" << aprice <<"\n";
else if (strcmp(partNum, "S147-29B") == 0)
cout << "The price is $" << Bprice << "\n";
else
cout << partNum << " is not a valid part number.\n";
getch();
}


example 3 :

// This program uses the return value of strcmp to
// alphabetically sort two strings entered by the user.

#include <iostream.h>
#include <string.h>

void main(void)
{
	char name1[30], name2[30];

	cout << "Enter a name (last name first): ";
	cin.getline(name1, 30);
	cout << "Enter another name: ";
	cin.getline(name2, 30);
cout << "Here are the names sorted alphabetically:\n";
	if (strcmp(name1, name2) < 0)
		cout << name1 << endl << name2 << endl;
	else if (strcmp(name1, name2) > 0)
		cout << name2 << endl << name1 << endl;	
	else
		cout << "You entered the same name twice!\n";
}


example 4:


//This program uses strcmp to compare the string entered
//by the user with the valid stereo part numbers.
#include<iostream.h>
#include<string>
using namespace std;

void main(void)
{
  const float aprice = 249.0, bprice = 299.0;
  string partNum;
  cout << "The stereo part numbers are:\n";
  cout << "Boom box, part number S147-29A\n";
  cout << "Shelf model, part number S147-29B\n";
  cout << "Enter the part number of the stereo you\n";
  cout << "wish to purchase: ";
  cin >> partNum;
cout.setf(ios::fixed | ios::showpoint);
  cout.precision(2);
  if (partNum == "S147-29A")
    cout << "The price is $" << aprice << endl;
  else if (partNum == "S147-29B")
    cout << "The price is $" << bprice << endl;
  else
    cout << partNum << " is not a valid part number.";
}


example 5 :
============
#include <iostream.h>
#include <conio.h>
void main(void)
{
clrscr();
float payRate = 50.0;
float hours, charges;

cout << "How many hours were worked? ";
cin >> hours;
hours = hours < 5 ? 5 : hours ;

charges = payRate * hours;	
cout << "The charges are $" << charges << "\n";

getch();
}



example 6
==========
// This program uses the return value of strcmp to alphabetically
// sort two strings entered by the user.

#include <iostream.h>
#include <string.h>

void main(void)
{
	char name1[30], name2[30];

	cout << "Enter a name (last name first): ";
	cin.getline(name1, 30);
cout << "Enter another name: ";
	cin.getline(name2, 30);
	cout << "Here are the names sorted alphabetically:\n";
	cout << (strcmp(name1, name2) <= 0 ? name1 : name2) << endl;
	cout << (strcmp(name1, name2) > 0 ? name1 : name2) << endl;
}



example7
=============

#include <iostream.h>
#include <conio.h>
void main(void)
{
clrscr();
	char choice;

	cout << "Enter A, B, or C: ";
	cin >> choice;
switch (choice)
	{
	case 'A':cout << "You entered A.\n";
		      break;
	case 'B':cout << "You entered B.\n";
	         	break;
	case 'C':	cout << "You entered C.\n";
		         	break;
default:cout << "You did not enter A, B, or C!\n";
	}
getch();
}




